package com.example.bootdemo.controller;

import com.example.bootdemo.entity.LayData;
import com.example.bootdemo.service.IUserService;
import com.example.bootdemo.util.Result;
import com.example.bootdemo.entity.User;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class UserController {
    @Resource
private IUserService service;
    @PostMapping("login")
public Result login(User user){
    System.out.println(user);
return new Result(null);
}
    @GetMapping("getAll")
    public Result getAll(){
        List<Map<String,String>> userList=new ArrayList<>();
        Map map=new HashMap();
        map.put("date","2016-05-02");
        map.put("name","李四");
        map.put("address","hhhh");
        userList.add(map);
        Map map2=new HashMap();
        map2.put("date","2016-05-02");
        map2.put("name","张三");
        map2.put("address","hhhh");
        userList.add(map2);
        Map map3=new HashMap();
        map3.put("date","2016-05-02");
        map3.put("name","王二");
        map3.put("address","hhhh");
        userList.add(map3);
        return new Result(userList);
    }
    @GetMapping("queryall")
    public LayData queryall(){
      return new LayData(service.queryall());
    }

    @PostMapping("add")
    public LayData add(User user){
        System.out.println(user);
        int add = service.add(user);
        if (add>0){
            return new LayData(true);
        }
        return new LayData(false);
    }
}
